import axios from '@/utils/axios'

export function getPage(params) {
  return axios({
    url: '/course/page',
    method: 'get',
    params
  })
}

export function getList() {
  return axios({
    url: '/course/list',
    method: 'get'
  })
}

export function getCourseListByType(params) {
  return axios({
    url: '/course/page/type',
    method: 'get',
    params
  })
}

/**
 * 获取今日课程
 */
export function getTodayCourse() {
  return axios({
    url: '/course/today',
    method: 'get'
  })
}

/**
 * 获取学生课程列表
 */
export function getStudentCourse() {
  return axios({
    url: '/course/student',
    method: 'get'
  })
}

export function getCourseById(id) {
  return axios({
    url: '/course/cs/' + id,
    method: 'get'
  })
}

export function getCourseType() {
  return axios({
    url: '/course/classify',
    method: 'get'
  })
}

export function getCourseAge() {
  return axios({
    url: '/course/age',
    method: 'get'
  })
}

export function addCourse(data) {
  return axios({
    url: '/course',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    transformRequest: [function(data) {
      // 对 data 进行任意转换处理
      return data
    }],
    data
  })
}

export function updateCourse(data) {
  return axios({
    url: '/course/update',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    transformRequest: [function(data) {
      // 对 data 进行任意转换处理
      return data
    }],
    data
  })
}

export function delCourse(id) {
  return axios({
    url: '/course/del_' + id,
    method: 'get'
  })
}

export function updateState(data) {
  return axios({
    url: '/course/state',
    method: 'post',
    data
  })
}

/**
 * 根据课程id查询用户是否已购买
 * @param id 课程id
 * @returns {*}
 */
export function checkBuyCourse(id) {
  return axios({
    url: '/course/check' + id,
    method: 'get'
  })
}

/**
 * 根据不同 用户角色获取课程列表
 */
export function getCourseListByRole() {
  return axios({
    url: '/course/courseList',
    method: 'get'
  })
}
